package com.weetop.cfw.base.presenter.imp

import com.blankj.utilcode.util.AppUtils
import com.weetop.cfw.base.presenter.VersionInfoPresenter
import com.weetop.cfw.base.view.BaseView
import com.weetop.cfw.base.view.VersionInfoView
import com.weetop.cfw.bean.AppVersionBean
import com.weetop.cfw.bean.SinglePageIntroduceBean
import com.weetop.cfw.callback.RxJavaCallBack
import com.weetop.cfw.mine.activity.VersionInfoActivity
import com.weetop.cfw.utils.RetrofitUtils
import com.weetop.cfw.utils.RxJavaUtils

class VersionInfoPresenterImp(var versionInfoView: VersionInfoView? = null):VersionInfoPresenter {


    /**
     * 获取APP功能介绍单页面
     */
    override fun getAppFunctionIntroduction(versionInfoActivity: VersionInfoActivity) {
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().getAppRelativeSinglePageIntroduce("appfunc"),versionInfoActivity,object:RxJavaCallBack<SinglePageIntroduceBean>(){

            override fun onSuccess(t: SinglePageIntroduceBean?) {
                versionInfoView?.appFunctionIntroductionGetSuccess(t)
            }

        })
    }

    /**
     * 检查APP版本信息
     */
    override fun checkAppVersionInfo(versionInfoActivity: VersionInfoActivity) {
        versionInfoActivity.showLoadingDialog(versionInfoActivity,"正在获取APP版本信息...")
        RxJavaUtils.useInAppCompatActivityOnDestory(RetrofitUtils.getApi().checkAppVersionInfo(AppUtils.getAppVersionCode()),versionInfoActivity,object:RxJavaCallBack<AppVersionBean>(){

            override fun onSuccess(t: AppVersionBean?) {
                versionInfoActivity.dismissLoadingDialog()
                versionInfoView?.appVersionInfoGetSuccess(t)
            }

            override fun onRequestError(t: AppVersionBean?) {
                super.onRequestError(t)
                versionInfoActivity.dismissLoadingDialog()
            }

            override fun onErrorResponse(throwable: Throwable?) {
                super.onErrorResponse(throwable)
                versionInfoActivity.dismissLoadingDialog()
            }

        })
    }

    /**
     * 绑定
     */
    override fun attachView(baseView: BaseView) {
        versionInfoView = baseView as? VersionInfoView
    }

    /**
     * 解绑
     */
    override fun detachView() {
       versionInfoView = null
    }
}